package org.example.spring_principle.contorller;

import jakarta.annotation.Resource;
import org.example.spring_principle.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/scope")
@RestController
public class ScopeController {
    @Autowired
    private Dog singleDog;
    @Autowired
    private Dog prototypeDog;
    @Autowired
    private ApplicationContext context;
    @Autowired
    private Dog requsetDog;
    @Autowired
    private Dog sessionDog;
    @Autowired
    private Dog applicationDog;
    @RequestMapping("/single")
    public String single() {
        Dog dog = (Dog) context.getBean("singleDog");
        return "注入对象："+singleDog.toString()+",context Dog"+dog.toString();
    }

    @RequestMapping("/prototype")
    public String prototype() {
        Dog dog = (Dog) context.getBean("prototypeDog");
        return "注入对象："+prototypeDog.toString()+",context Dog"+dog.toString();
    }
    @RequestMapping("/requset")
    public String requset() {
        Dog dog = (Dog) context.getBean("requsetDog");
        return "注入对象："+requsetDog.toString()+",context Dog"+dog.toString();
    }
    @RequestMapping("/session")
    public String session() {
        Dog dog = (Dog) context.getBean("sessionDog");
        return "注入对象："+sessionDog.toString()+",context Dog"+dog.toString();
    }
    @RequestMapping("/application")
    public String application() {
        Dog dog = (Dog) context.getBean("applicationDog");
        return "注入对象："+applicationDog.toString()+",context Dog"+dog.toString();
    }
}
